package com.sy.simpleegg.room.repository

import com.sy.simpleegg.room.dao.ControlBoardDao
import com.sy.simpleegg.room.entity.ControlBoardEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class ControlBoardRepository(private val controlBoardDao: ControlBoardDao) {

    suspend fun getAll(): MutableList<ControlBoardEntity>?{
        return withContext(Dispatchers.IO){
            controlBoardDao.getAll()
        }
    }

    suspend fun getLast(type: Int): MutableList<ControlBoardEntity>?{
        return withContext(Dispatchers.IO){
            controlBoardDao.getLast(type)
        }
    }

    suspend fun insert(controlBoardEntity: ControlBoardEntity){
        withContext(Dispatchers.IO){
            controlBoardDao.insert(controlBoardEntity)
        }
    }

    suspend fun delete(controlBoardEntity: ControlBoardEntity){
        withContext(Dispatchers.IO){
            controlBoardDao.delete(controlBoardEntity)
        }
    }

    suspend fun deleteAll(){
        withContext(Dispatchers.IO){
            controlBoardDao.deleteAll()
        }
    }

    suspend fun getDateData(type: Int, date: String): MutableList<ControlBoardEntity>?{
        return withContext(Dispatchers.IO){
            controlBoardDao.getDateData(type, date)
        }
    }

    suspend fun getBetweenDate(type: Int, startDate: String, endDate: String): MutableList<ControlBoardEntity>?{
        return withContext(Dispatchers.IO){
            controlBoardDao.getBetweenDate(type, startDate, endDate)
        }
    }
}